package com.simplenix.nicasio.mb;

import com.simplenix.nicasio.admin.eb.User;
import com.simplenix.nicasio.misc.AppException;
import com.simplenix.nicasio.misc.Internationalization;
import com.simplenix.nicasio.misc.StrUtil;
import javax.faces.context.FacesContext;

/**
 *
 * @author fronald
 */
public class Session {

	public static final String CURRENT_USER = "CURRENT_USER";

	public static final String FLASH_MESSAGE = "FLASH_MESSAGE";

	/** Creates a new instance of Session */
	public Session() {
	}

	public User getCurrentUser() {
		return (User) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(CURRENT_USER);
	}

	public String getFlashMessage() {
		String flash = StrUtil.nvl((String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(FLASH_MESSAGE));
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(FLASH_MESSAGE);
		return flash;
	}

	public String getLogout() throws AppException {
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(CURRENT_USER);
		return Internationalization.getInstance().getString("logout.message");
	}

}
